package me.innolux.daxin_nesting.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.innolux.daxin_nesting.pojo.dto.AGVTaskContinueExecuteDto;
import me.innolux.daxin_nesting.pojo.dto.AgvTaskSubmitDto;
import me.innolux.daxin_nesting.pojo.dto.NoticeAgvDto;
import me.innolux.daxin_nesting.pojo.vo.AgvTaskSubmitVo;
import me.innolux.daxin_nesting.pojo.vo.TaskSubmitData;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping
@RequiredArgsConstructor
@Slf4j
public class AgvController {

    @PostMapping("/api/robot/controller/task/submit")
    public AgvTaskSubmitVo agvTaskSubmit(@RequestBody AgvTaskSubmitDto agvTaskSubmitDto){
        log.info("任务下发请求参数：{}",agvTaskSubmitDto);
        TaskSubmitData taskSubmitData = new TaskSubmitData();
        taskSubmitData.setRobotTaskCode(agvTaskSubmitDto.getRobotTaskCode());
        AgvTaskSubmitVo agvTaskSubmitVo = new AgvTaskSubmitVo();
        agvTaskSubmitVo.setCode("SUCCESS");
        agvTaskSubmitVo.setMessage("成功");
        agvTaskSubmitVo.setData(taskSubmitData);
        log.info("任务下发返回报文：{}",agvTaskSubmitVo);
        return agvTaskSubmitVo;
    }

    @PostMapping("/api/robot/controller/task/extend/continue")
    public AgvTaskSubmitVo taskContinueExecute(@RequestBody AGVTaskContinueExecuteDto agvTaskContinueExecuteDto){
        log.info("任务继续执行请求参数：{}",agvTaskContinueExecuteDto);
        TaskSubmitData taskSubmitData = new TaskSubmitData();
        taskSubmitData.setRobotTaskCode(agvTaskContinueExecuteDto.getRobotTaskCode());
        AgvTaskSubmitVo agvTaskSubmitVo = new AgvTaskSubmitVo();
        agvTaskSubmitVo.setCode("SUCCESS");
        agvTaskSubmitVo.setMessage("成功");
        agvTaskSubmitVo.setData(taskSubmitData);
        log.info("任务继续返回报文：{}",agvTaskSubmitVo);
        return agvTaskSubmitVo;
    }

    //外设执行通知
    @PostMapping("/spi/wcs/robot/eqpt/notify")
    public AgvTaskSubmitVo taskContinueExecute(@RequestBody NoticeAgvDto noticeAgvDto){
        log.info("外设执行通知请求参数：{}",noticeAgvDto);
        TaskSubmitData taskSubmitData = new TaskSubmitData();
        taskSubmitData.setRobotTaskCode(noticeAgvDto.getTaskCode());
        AgvTaskSubmitVo agvTaskSubmitVo = new AgvTaskSubmitVo();
        agvTaskSubmitVo.setCode("SUCCESS");
        agvTaskSubmitVo.setMessage("成功");
        agvTaskSubmitVo.setData(taskSubmitData);
        log.info("外设执行通知返回报文：{}",agvTaskSubmitVo);
        return agvTaskSubmitVo;
    }
}
